﻿using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace EHR18
{
    public partial class FrmLogin : BaseChild
    {
        Common.GenneralConfig g_Config = Common.GenneralConfig.instance;
        public FrmLogin()
        {
            InitializeComponent();
            instance = this;

        }

        public static Form instance;
        Form dis;

        public string CheckWelcomeInputValid()
        {
            string valid = "OK";
             if (this.comboBox1.Text == string.Empty)
            {
                valid = "产品型号为空";
            }
            else if (this.textBox2.Text == string.Empty)
            {
                valid = "操作员为空";
            }
            return valid;

        }
        private void StartTestPage()
        {
            string valid = CheckWelcomeInputValid();
            if (valid != "OK")
            {
                if (ShowQuestion(valid + "，是否继续？") != DialogResult.Yes)
                    return;
            }
            if (dis == null)
            {
                this.Visible = false;
                dis = new FormMain();
                //   dis.ModelName = this.comboBox1.Text;
                dis.Show();
            }


        }
        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (ShowQuestion("真的要退出吗？") == DialogResult.Yes)
            {
                Application.Exit();
            }
        }
        private void btnSetting_Click(object sender, EventArgs e)
        {
            FrmModulesConfig frmCfg = new FrmModulesConfig();
            frmCfg.ShowDialog();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            UIData_Load();

        }
        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                SendKeys.Send("{tab}");
            }
        }

        private void UIData_Load()
        {
            comboBox1.Text = g_Config.CurrentModel;
         //   textBox1.Text = g_Config.MO.Split('-')[0];
            textBox2.Text = g_Config.OperID;
            string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory+"Configs", "*.xml");
            comboBox1.Items.Clear();
            if (files.Count() > 0)
            {
                foreach (string file in files)
                {
                    Name = Path.GetFileNameWithoutExtension(file);
                    comboBox1.Items.Add(Name);
                }
            }
        }
        private void buttonX1_Click(object sender, EventArgs e)
        {
            UIData_Save();
            g_Config.LoadModuleConfig();
            StartTestPage();
        }

        private void UIData_Save()
        {
            g_Config.CurrentModel = this.comboBox1.Text;
            g_Config.MO = textBox1.Text;
            g_Config.OperID = this.textBox2.Text;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            g_Config.CurrentModel = comboBox1.Text;
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            g_Config.CurrentModel = this.comboBox1.Text;
        }
    }
}
